import request from '@/service/request';
import type { IPageQsTemplate, IQsTemplate } from './types';

// 分页请求模板列表
export function requestPageQsTemplate(params: { pageNum: number; pageSize: number }) {
  return request.get<IPageQsTemplate>({
    url: '/QsTemplate/getPageQsTemplate',
    params,
    interceptors: {
      responseInterceptor(res: any): IPageQsTemplate {
        return {
          records: res?.data?.list,
          total: res?.data?.total,
        };
      },
    },
  });
}

// 新增模板
export function addQsTemplate(data: IQsTemplate) {
  return request.post({
    url: '/QsTemplate/addQsTemplate',
    data,
    headers: { 'Content-Type': 'application/json' },
  });
}

// 保存模板
export function saveQsTemplate(data: IQsTemplate) {
  return request.post({
    url: '/QsTemplate/saveQsTemplate',
    data,
    headers: { 'Content-Type': 'application/json' },
  });
}

// 发布模板
export function editQsTemplate(data: IQsTemplate) {
  return request.post({
    url: '/QsTemplate/editQsTemplate',
    data,
    headers: { 'Content-Type': 'application/json' },
  });
}

// 根据id查询模板
export function queryQsTemplate(id: number | string) {
  return request.get<IQsTemplate>({
    url: `/QsTemplate/${id}`,
    interceptors: {
      responseInterceptor(res: any): IQsTemplate {
        return res?.data;
      },
    },
  });
}

// 根据多个id查询多个模板
export function queryMultipleTemplate(ids: string) {
  return request.get<IQsTemplate[]>({
    url: '/QsTemplate/queryMultipleTemplate',
    params: { ids },
    interceptors: {
      responseInterceptor(res: any): IQsTemplate[] {
        return res?.data;
      },
    },
  });
}

// 根据id删除模板
export function deleteQsTemplate(id: number | string) {
  return request.delete({
    url: `/QsTemplate/${id}`,
  });
}

// 根据id复制模板
export function copyQsTemplate(id: number | string) {
  return request.get({
    url: '/QsTemplate/copyQsTemplate',
    params: { id },
  });
}

// 根据id发布模板
export function releaseQsTemplate(id: number | string) {
  return request.get({
    url: '/QsTemplate/publishTemplate',
    params: { id },
  });
}

// 获取全部模板
export function getAllQsTemplate() {
  return request.get<IQsTemplate[]>({
    url: '/QsTemplate/getAllQsTemplate',
    interceptors: {
      responseInterceptor(res: any): IQsTemplate[] {
        return res?.data;
      },
    },
  });
}
